﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Final_Prototype_UsingDev_QuanLy_071012
{
    public partial class Form_Quotation_New_Quotation : Form
    {
        Form_Custom_Management_Add _frAdd;
        public Form_Quotation_New_Quotation(Form_Custom_Management_Add frAdd)
        {
            InitializeComponent();
            _frAdd = frAdd;
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            //Form fr1 = new Form_Quotation_Edit_Transit();
            //fr1.Show();
        }

        private void barButtonItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {

        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            //Form fr1 = new Form_Quotation_Add_Transit();
            //fr1.Show();
        }

        private void label11_Click(object sender, EventArgs e)
        {

        }

        private void cboTransitType_SelectedIndexChanged(object sender, EventArgs e)
        {
            string check1 = cboTransitType.SelectedItem.ToString();
            if (check1 == "")
            {

                lblCheckTransitType.Visible = true;

            }
            else
            {

                lblCheckTransitType.Visible = false;

            };
            if (checkRequire())
                btnAddTransitType.Enabled = true;
            else
                btnAddTransitType.Enabled = false;
        }

        private void cboFreight_SelectedIndexChanged(object sender, EventArgs e)
        {
            string check1 = cboFreight.SelectedItem.ToString();
            if (check1 == "")
            {

                lblCheckFreight.Visible = true;

            }
            else
            {

                lblCheckFreight.Visible = false;

            };
            if (checkRequire())
                btnAddTransitType.Enabled = true;
            else
                btnAddTransitType.Enabled = false;
        }

        private void txtTransitTime_TextChanged(object sender, EventArgs e)
        {
            if (txtTransitTime.Text == "")
            {
                lblCheckTransitTime.Visible = true;
            }
            else
            {
                lblCheckTransitTime.Visible = false;
                if (checkRequire())
                    btnAddTransitType.Enabled = true;

                else
                    btnAddTransitType.Enabled = false;
            }
        }

        private void txtFrequency_TextChanged(object sender, EventArgs e)
        {
            if (txtFrequency.Text == "")
            {
                lblCheckFrequency.Visible = true;
            }
            else
            {
                lblCheckFrequency.Visible = false;
                if (checkRequire())
                    btnAddTransitType.Enabled = true;

                else
                    btnAddTransitType.Enabled = false;
            }
        }

        private void cboItem_SelectedIndexChanged(object sender, EventArgs e)
        {
            string check1 = cboItem.SelectedItem.ToString();
            if (check1 == "")
            {

                lblCheckItem.Visible = true;

            }
            else
            {

                lblCheckItem.Visible = false;

            };
            if (checkRequire())
                btnAddTransitType.Enabled = true;
            else
                btnAddTransitType.Enabled = false;
        }

        private void cboCurrency_SelectedIndexChanged(object sender, EventArgs e)
        {
            string check1 = cboCurrency.SelectedItem.ToString();
            if (check1 == "")
            {

                lblCheckCurrency.Visible = true;

            }
            else
            {

                lblCheckCurrency.Visible = false;

            };
            if (checkRequire())
                btnAddTransitType.Enabled = true;
            else
                btnAddTransitType.Enabled = false;
        }

        private void cboUnit_SelectedIndexChanged(object sender, EventArgs e)
        {
            string check1 = cboUnit.SelectedItem.ToString();
            if (check1 == "")
            {

                lblCheckUnit.Visible = true;

            }
            else
            {

                lblCheckUnit.Visible = false;

            };
            if (checkRequire())
                btnAddTransitType.Enabled = true;
            else
                btnAddTransitType.Enabled = false;
        }

        //CHECK REQUIRE FUCTION
        private bool checkRequire()
        {
            int temp = txtTransitTime.Text.Length * txtFrequency.Text.Length * cboTransitType.Text.Length * cboFreight.Text.Length * cboItem.Text.Length * cboCurrency.Text.Length * cboUnit.Text.Length;
            if (temp != 0)
                return true;

            return false;
        }

        private void Form_Quotation_New_Quotation_Load(object sender, EventArgs e)
        {
            txtCompanyName.Text = _frAdd.cs.CompanyName;
            txtCustomerName.Text = _frAdd.cs.ContactPerson;
            txtFax.Text = _frAdd.cs.Fax;
            cboCustomerCode.Text = _frAdd.cs.CustomerCode;
            rtbAddress.Text = _frAdd.cs.Address;
            txtTel.Text = _frAdd.cs.Tel;
        }
    }
}